package com.woupla.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * Entity implementation class for Entity: Company
 * 
 */
@NamedQueries(
		{ @NamedQuery(name = "findAllCity", query = "SELECT c FROM City c ") ,
		 @NamedQuery(name = "findAllCityInDep", query = "SELECT c FROM City c, Departement d where d.label like :dep ") ,
		 @NamedQuery(name = "findAllCityInReg", query = "SELECT c FROM City c"),
		 @NamedQuery(name = "findAllCityLike", query = "SELECT c FROM City c WHERE c.label like :city"),
		 @NamedQuery(name = "findAllCityLabel", query = "SELECT c FROM City c WHERE c.label = :city"),
		 @NamedQuery(name = "findAllCityCP", query = "SELECT c FROM City c WHERE c.codePostal = :cp "),
		 @NamedQuery(name = "findAllCityByCPAndLabel", query = "SELECT c FROM City c WHERE c.codePostal = :cp AND c.label = :label"),
		 @NamedQuery(name = "city.findAllCityLikeCpOrLabel", query = "SELECT c FROM City c WHERE c.codePostal LIKE :value OR c.label LIKE :value"),
		 @NamedQuery(name = "findAllCityLikeCP", query = "SELECT c FROM City c WHERE c.codePostal like :cp group by c.codePostal")}
		)
@Entity
public class City implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4714055814360473722L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	@NotNull
	@NotEmpty
	private String label;
	@NotNull
	@NotEmpty
	private String codeINSEE;
	@NotNull
	@NotEmpty
	private String codePostal;
	@ManyToOne
	@JoinColumn(referencedColumnName="id")
	private Departement departement;

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the codeINSEE
	 */
	public String getCodeINSEE() {
		return codeINSEE;
	}

	/**
	 * @param codeINSEE
	 *            the codeINSEE to set
	 */
	public void setCodeINSEE(String codeINSEE) {
		this.codeINSEE = codeINSEE;
	}

	/**
	 * @return the codePostal
	 */
	public String getCodePostal() {
		return codePostal;
	}

	/**
	 * @param codePostal
	 *            the codePostal to set
	 */
	public void setCodePostal(String codePostal) {
		this.codePostal = codePostal;
	}

	/**
	 * @return the departement
	 */
	public Departement getDepartement() {
		return departement;
	}

	/**
	 * @param departement
	 *            the departement to set
	 */
	public void setDepartement(Departement departement) {
		this.departement = departement;
	}

	/**
	 * @return the label
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * @param label the label to set
	 */
	public void setLabel(String label) {
		this.label = label;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "City [id=" + id + ", label=" + label + ", codeINSEE="
				+ codeINSEE + ", codePostal=" + codePostal + ", departement="
				+ departement + "]";
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((codePostal == null) ? 0 : codePostal.hashCode());
		result = prime * result
				+ ((departement == null) ? 0 : departement.hashCode());
		result = prime * result + ((label == null) ? 0 : label.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		City other = (City) obj;
		if (codePostal == null) {
			if (other.codePostal != null)
				return false;
		} else if (!codePostal.equals(other.codePostal))
			return false;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}

	

}
